﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VIBlend.WPF.Controls;

namespace AnonsaiWPF.CSharp.TabControl
{
    public partial class GroupBoxOverview : Window, IWindow
    {
        public GroupBoxOverview()
        {
            InitializeComponent();
            this.primaryTop.Checked += new RoutedEventHandler(primaryAlignment_Checked);
            this.primaryLeft.Checked += new RoutedEventHandler(primaryAlignment_Checked);
            this.primaryRight.Checked += new RoutedEventHandler(primaryAlignment_Checked);
            this.primaryBottom.Checked += new RoutedEventHandler(primaryAlignment_Checked);

            this.secondaryTop.Checked += new RoutedEventHandler(secondaryAlignment_Checked);
            this.secondaryLeft.Checked += new RoutedEventHandler(secondaryAlignment_Checked);
            this.secondaryRight.Checked += new RoutedEventHandler(secondaryAlignment_Checked);
            this.secondaryBottom.Checked += new RoutedEventHandler(secondaryAlignment_Checked);

            this.showPrimaryHeader.Checked += new RoutedEventHandler(showPrimaryHeader_Checked);
            this.showPrimaryHeader.Unchecked += new RoutedEventHandler(showPrimaryHeader_Unchecked);
            this.showSecondaryHeader.Checked += new RoutedEventHandler(showSecondaryHeader_Checked);
            this.showSecondaryHeader.Unchecked += new RoutedEventHandler(showSecondaryHeader_Unchecked);

            this.groupBox1.IsCollapsedChanged += new EventHandler(groupBox1_IsCollapsedChanged);
        }

        public void DetachContent()
        {
            RemoveLogicalChild(Content);
        }

    
        public void SetTheme()
        {
        }

        public Grid Root
        {
            get
            {
                return this.RootVisual;
            }
        }

        void groupBox1_IsCollapsedChanged(object sender, EventArgs e)
        {
            if (this.groupBox1 != null)
            {
                this.checkBox4.IsChecked = this.groupBox1.IsCollapsed;
                switch (this.groupBox1.CollapseMode)
                {
                    case GroupBoxCollapseMode.CollapseToPrimaryHeader:
                        this.showPrimaryHeader.IsChecked = true;
                        break;
                    case GroupBoxCollapseMode.CollapseToSecondaryHeader:
                        this.showSecondaryHeader.IsChecked = true;
                        break;
                    case GroupBoxCollapseMode.CollapseToBothHeaders:
                        this.showPrimaryHeader.IsChecked = true;
                        this.showSecondaryHeader.IsChecked = true;
                        break;
                }
            }
        }

        void showSecondaryHeader_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.showSecondaryHeader != null && this.groupBox1 != null)
            {
                this.groupBox1.ShowSecondaryHeader = this.showSecondaryHeader.IsChecked.Value;
            }
        }

        void showSecondaryHeader_Checked(object sender, RoutedEventArgs e)
        {
            if (this.showSecondaryHeader != null && this.groupBox1 != null)
            {
                this.groupBox1.ShowSecondaryHeader = this.showSecondaryHeader.IsChecked.Value;
            }
        }

        void showPrimaryHeader_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.showPrimaryHeader != null && this.groupBox1 != null)
            {
                this.groupBox1.ShowPrimaryHeader = this.showPrimaryHeader.IsChecked.Value;
            }
        }

        void showPrimaryHeader_Checked(object sender, RoutedEventArgs e)
        {
            if (this.showPrimaryHeader != null && this.groupBox1 != null)
            {
                this.groupBox1.ShowPrimaryHeader = this.showPrimaryHeader.IsChecked.Value;
            }
        }

        void secondaryAlignment_Checked(object sender, RoutedEventArgs e)
        {
            ApplySecondaryAlignment();
        }

        private void ApplySecondaryAlignment()
        {
            if (this.secondaryRight == null)
                return;

            if (this.secondaryBottom == null)
                return;

            if (this.secondaryLeft == null)
                return;

            if (this.secondaryTop == null)
                return;

            if (this.groupBox1 == null)
                return;

            if (this.secondaryTop.IsChecked.Value)
            {
                this.groupBox1.HeaderPositionSecondary = Position.Top;

                if (this.groupBox1.CollapseMode == GroupBoxCollapseMode.CollapseToSecondaryHeader)
                {
                    this.groupBox1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    this.groupBox1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                }
            }
            else if (this.secondaryRight.IsChecked.Value)
            {
                this.groupBox1.HeaderPositionSecondary = Position.Right;
                if (this.groupBox1.CollapseMode == GroupBoxCollapseMode.CollapseToSecondaryHeader)
                {
                    this.groupBox1.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    this.groupBox1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                }
            }
            else if (this.secondaryLeft.IsChecked.Value)
            {
                this.groupBox1.HeaderPositionSecondary = Position.Left;
                if (this.groupBox1.CollapseMode == GroupBoxCollapseMode.CollapseToSecondaryHeader)
                {
                    this.groupBox1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    this.groupBox1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                }
            }
            else if (this.secondaryBottom.IsChecked.Value)
            {
                this.groupBox1.HeaderPositionSecondary = Position.Bottom;
                if (this.groupBox1.CollapseMode == GroupBoxCollapseMode.CollapseToSecondaryHeader)
                {
                    this.groupBox1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    this.groupBox1.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
                }
            }
        }

        void primaryAlignment_Checked(object sender, RoutedEventArgs e)
        {
            ApplyPrimaryAlignment();
        }

        private void ApplyPrimaryAlignment()
        {
            if (this.primaryTop == null)
                return;

            if (this.primaryLeft == null)
                return;

            if (this.primaryRight == null)
                return;

            if (this.primaryBottom == null)
                return;

            if (this.groupBox1 == null)
                return;

            if (this.primaryTop.IsChecked.Value)
            {
                this.groupBox1.HeaderPositionPrimary = Position.Top;
                if (this.groupBox1.CollapseMode != GroupBoxCollapseMode.CollapseToSecondaryHeader)
                {
                    this.groupBox1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    this.groupBox1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                }
            }
            else if (this.primaryRight.IsChecked.Value)
            {
                this.groupBox1.HeaderPositionPrimary = Position.Right;
                if (this.groupBox1.CollapseMode != GroupBoxCollapseMode.CollapseToSecondaryHeader)
                {
                    this.groupBox1.HorizontalAlignment = System.Windows.HorizontalAlignment.Right;
                    this.groupBox1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                }
            }
            else if (this.primaryLeft.IsChecked.Value)
            {
                this.groupBox1.HeaderPositionPrimary = Position.Left;
                if (this.groupBox1.CollapseMode != GroupBoxCollapseMode.CollapseToSecondaryHeader)
                {
                    this.groupBox1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    this.groupBox1.VerticalAlignment = System.Windows.VerticalAlignment.Top;
                }
            }
            else if (this.primaryBottom.IsChecked.Value)
            {
                this.groupBox1.HeaderPositionPrimary = Position.Bottom;
                if (this.groupBox1.CollapseMode != GroupBoxCollapseMode.CollapseToSecondaryHeader)
                {
                    this.groupBox1.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                    this.groupBox1.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
                }
            }
        }

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.CollapseMode = GroupBoxCollapseMode.CollapseToPrimaryHeader;
            ApplySecondaryAlignment();
            ApplyPrimaryAlignment();
        }

        private void RadioButton_Checked_1(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.CollapseMode = GroupBoxCollapseMode.CollapseToSecondaryHeader;
            ApplySecondaryAlignment();
            ApplyPrimaryAlignment();
        }

        private void RadioButton_Checked_2(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.CollapseMode = GroupBoxCollapseMode.CollapseToBothHeaders;
            ApplySecondaryAlignment();
            ApplyPrimaryAlignment();
        }

        private void checkBox4_Checked(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.IsCollapsed = true;
        }

        private void checkBox4_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.IsCollapsed = false;
        }

        private void checkBox6_Checked(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.IsHighlightStateEnabled = true;
        }

        private void checkBox6_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.IsHighlightStateEnabled = false;
        }

        private void checkBox1_Checked(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.ShowCollapseArrow = true;
        }

        private void checkBox1_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.ShowCollapseArrow = false;
        }

        private void checkBox5_Checked(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.IsExpandCollapseAnimationEnabled = true;
        }

        private void checkBox5_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.groupBox1 == null)
                return;

            this.groupBox1.IsExpandCollapseAnimationEnabled = false;
        }
    }
}
